var view = new Vue({
    el: '#view',
    data: {
        imgurl: imgurl,
        ffList: [],
        ffInfo: {},
        listData: {
            name: '',
            city: '',
            offten_city: '',
            age: '',
            occupation: '',
            dy_program: '',
            dy_conditions: '',
            wxcount: '',
            qq: '',
            stature: '',
            weight: '',
            self_slogan: ''
        },
        kejian: 0, // 0 可见 1不可见
    },
    methods: {
        _url: function (param, url) {
            _url(param, url);
        },
        // 图片自适应
        imgCss: function (url, event) {
            var e = event.currentTarget;
            imgCss(url, function (w, h) {
                if (w < h) {
                    $(e).parent().addClass('img-w').removeClass('img-h');
                }
            })
        },
    }
})
getUserInfo();

// 修改
function getUserFilter(ziduan, value) {
    view.listData[ziduan] = value;
    closeModalFrm();
}

var cityLen = 1; // 1 当前城市 4常驻城市
function _changeCity(city) {
    if (cityLen == 1) {
        view.listData.city = city;
    } else {
        view.listData.offten_city = city;
    }
    closeModalFrm();
}
// 修改当前城市
function _showCity(len) {
    cityLen = len;
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'frame0/city');
}

// 多选
var ziduanType;

function openFilter(ziduan) {
    ziduanType = ziduan;
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'user/user_filter');
}


// 单选
var singleArr = [];

function openSingle(ziduan, type, title, arr) {
    ziduanType = ziduan;
    var btnArr = [];
    if (type == 1) { // 单选 规则
        for (var i = arr[0]; i < arr[1]; i++) {
            var obj = {
                "name": i
            };
            btnArr.push(obj);
        }
    } else { // 单选 不规则
        btnArr = _paramObj[ziduan];
    }
    singleArr = btnArr;
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'frame0/single');
}

// 隐藏模态框
function closeModalFrm() {
    $('#modal-wrap').addClass('new-hide');
}

// 获取个人资料
function getUserInfo() {
    _getUser(function (ret) {
        for (var key in view.listData) {
            view.listData[key] = ret.result[key] == 'null' ? '' : ret.result[key] || '';
        }
        _log(JSON.stringify(view.listData))
        setCookie('myyue', ret.result.volley);
    })
}
judgeLogin()
// 提交个人资料
$('#js-winmore').on('click', function () {
    var keyLen = 0;
    _log(JSON.stringify(view.listData));
    if(!view.listData.wxcount && !view.listData.qq){
        _msg('微信和qq至少填写一个');
        return;
    }
    for (var key in view.listData) {
        keyLen++;
        // if(key == 'dy_program' || key == 'dy_conditions'){
        //     var obj = { user_id: myuserid, ziduan: key, value: view.listData[key].join(',') }
        // }else{
        var obj = {
            user_id: myuserid,
            ziduan: key,
            value: view.listData[key]
        }
        // }
        _ajax('user_info_edit.php', function (ret, err) {
            _log(JSON.stringify(ret))
            _log(JSON.stringify(err))
        }, obj)
        _log(keyLen)
        if (keyLen == Object.keys(view.listData).length) {
            _msg('修改成功');
            timerWin();
        }
    }
})

// 修改社交账号是否显示
function changeSocial() {
    view.kejian = view.kejian == 1 ? 0 : 1;
    _ajax('user_info_edit.php', function (ret, err) {
        _log(JSON.stringify(ret))
        _log(JSON.stringify(err))
    }, {
        user_id: $api.getStorage('userid'),
        ziduan: 'kejian',
        value: view.kejian
    })
}